<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="lib/jquery-3.3.1.js"></script>
    <style>
   #granpa{
       width:400px;
       height:400px;
       position: absolute;
       left:100px;
       margin-top: 100px;
       background: red;
   }
   #parent{
       width:200px;
       height:200px;
       background: yellow;
       top:50px;
       margin-top: 50px;
       position: absolute;
   }
   #child{
       width:100px;
       height:100px;
       background: green;
       position: absolute;
       margin-top: 50px;
       left:20px;
   }
   *{margin:0;padding:0;}
</style>
</head> 
<body>
    <div id="granpa">
        <div id="parent">
            <div id="child"></div>
        </div>
    </div>
<script>
$(()=>{
    var top=$("child").offset()
    console.log(top);
})

window.onload=function(){
    function gettop(element)
}
</script>

</body>
</html>